using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using Entities;
/// <summary>
/// Summary description for DoanhThuGhiDanhDAL
/// </summary>
namespace DataAccess
{

    public class DoanhThuGhiDanhDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public DoanhThuGhiDanhDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion

        #region Public Methods
        public int Insert(DoanhThuGhiDanh objDoanhThuGhiDanh)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_DoanhThuGhiDanh_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@KhoaHoc", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.KhoaHoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.HangXe;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DoiTuongGhiDanh", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.DoiTuongGhiDanh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SoTienHocChinhThuc", SqlDbType.Decimal);
            Sqlparam.Value = objDoanhThuGhiDanh.SoTienHocChinhThuc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SoTienHocNgoaiGio", SqlDbType.Decimal);
            Sqlparam.Value = objDoanhThuGhiDanh.SoTienHocNgoaiGio;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(DoanhThuGhiDanh objDoanhThuGhiDanh)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_DoanhThuGhiDanh_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@KhoaHoc", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.KhoaHoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.HangXe;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DoiTuongGhiDanh", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.DoiTuongGhiDanh;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SoTienHocChinhThuc", SqlDbType.Decimal);
            Sqlparam.Value = objDoanhThuGhiDanh.SoTienHocChinhThuc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SoTienHocNgoaiGio", SqlDbType.Decimal);
            Sqlparam.Value = objDoanhThuGhiDanh.SoTienHocNgoaiGio;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(DoanhThuGhiDanh objDoanhThuGhiDanh)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_DoanhThuGhiDanh_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@KhoaHoc", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.KhoaHoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.HangXe;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DoiTuongGhiDanh", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.DoiTuongGhiDanh;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_DoanhThuGhiDanh_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public DoanhThuGhiDanh Select(DoanhThuGhiDanh objDoanhThuGhiDanh)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_DoanhThuGhiDanh_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@KhoaHoc", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.KhoaHoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.HangXe;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DoiTuongGhiDanh", SqlDbType.BigInt);
            Sqlparam.Value = objDoanhThuGhiDanh.DoiTuongGhiDanh;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["KhoaHoc"]))
                    objDoanhThuGhiDanh.KhoaHoc = Convert.ToInt64(dr["KhoaHoc"]);
                if (!Convert.IsDBNull(dr["HangXe"]))
                    objDoanhThuGhiDanh.HangXe = Convert.ToInt64(dr["HangXe"]);
                if (!Convert.IsDBNull(dr["DoiTuongGhiDanh"]))
                    objDoanhThuGhiDanh.DoiTuongGhiDanh = Convert.ToInt64(dr["DoiTuongGhiDanh"]);
                if (!Convert.IsDBNull(dr["SoTienHocChinhThuc"]))
                    objDoanhThuGhiDanh.SoTienHocChinhThuc = Convert.ToDecimal(dr["SoTienHocChinhThuc"]);
                if (!Convert.IsDBNull(dr["SoTienHocNgoaiGio"]))
                    objDoanhThuGhiDanh.SoTienHocNgoaiGio = Convert.ToDecimal(dr["SoTienHocNgoaiGio"]);

            }
            return objDoanhThuGhiDanh;
        }

        public ArrayList SelectAllToArray()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_DoanhThuGhiDanh_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrDoanhThuGhiDanh = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    DoanhThuGhiDanh objDoanhThuGhiDanh = new DoanhThuGhiDanh();
                    if (!Convert.IsDBNull(dr["KhoaHoc"]))
                        objDoanhThuGhiDanh.KhoaHoc = Convert.ToInt64(dr["KhoaHoc"]);
                    if (!Convert.IsDBNull(dr["HangXe"]))
                        objDoanhThuGhiDanh.HangXe = Convert.ToInt64(dr["HangXe"]);
                    if (!Convert.IsDBNull(dr["DoiTuongGhiDanh"]))
                        objDoanhThuGhiDanh.DoiTuongGhiDanh = Convert.ToInt64(dr["DoiTuongGhiDanh"]);
                    if (!Convert.IsDBNull(dr["SoTienHocChinhThuc"]))
                        objDoanhThuGhiDanh.SoTienHocChinhThuc = Convert.ToDecimal(dr["SoTienHocChinhThuc"]);
                    if (!Convert.IsDBNull(dr["SoTienHocNgoaiGio"]))
                        objDoanhThuGhiDanh.SoTienHocNgoaiGio = Convert.ToDecimal(dr["SoTienHocNgoaiGio"]);
                    arrDoanhThuGhiDanh.Add(objDoanhThuGhiDanh);
                }
            }
            return arrDoanhThuGhiDanh;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_DoanhThuGhiDanh_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
